#import json
## We assume ks_meta contains repo_setup variable
## Cleaning up sources.list
echo > /target/etc/apt/sources.list; \
mkdir -p /target/etc/apt/sources.list.d; \
mkdir -p /target/etc/apt/preferences.d; \
#set $repo_setup = json.loads($getVar("repo_setup"))
#set $repos = $repo_setup["repos"]
#for $repo in $repos
echo 'deb $repo["uri"] $repo["suite"] $repo["section"]' > /target/etc/apt/sources.list.d/${repo["name"]}.list; \
#if not $repo.get("priority")
  #continue
#end if
echo 'Package: *' > /target/etc/apt/preferences.d/$repo["name"]; \
echo 'Pin: release a=$repo["suite"]' >> /target/etc/apt/preferences.d/$repo["name"]; \
echo 'Pin-Priority: $repo["priority"]' >> /target/etc/apt/preferences.d/$repo["name"]; \
echo '' >> /target/etc/apt/preferences.d/$repo["name"]; \
#end for
